package algotithm.leetcode.bytedance.test991;

/**
 * @author zhouyanxiang
 * @Date 2021-03-2021/3/10-15:27
 * @URL https://leetcode-cn.com/problems/broken-calculator/
 * @Title 991. 坏了的计算器
 */
public class Solution {

    public static void main(String[] args) {
        int X = 2;
        int Y = 3;
        Solution solution = new Solution();
        int ans = solution.brokenCalc(X,Y);
        System.out.println(ans);
    }

    public int brokenCalc(int X, int Y) {
        int ans = 0;
        while (Y > X) {
            ans++;
            if (Y % 2 == 1) {
                Y += 1;
            } else {
                Y /= 2;
            }
        }
        return ans + X - Y;
    }

}
